<?php

class Core_Backend_Component_Promotion_View_Concessions_Category_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('promotion/concessions/category-index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'category-apply') . "')");
        $group->addButton($this->__('share.button.save'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'category-save') . "')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('category_form')
                ->addHiddenField('id', 'category[id]');
        $form->addTextboxField($this->__('share.label.name'), 'name', 'category[name]', TRUE)->addValidateRule('required');
        $form->addSelectField($this->__('share.label.theme'), 'theme_id', 'category[theme_id]', TRUE)
                ->bindData($this->getThemes(), 'title', 'id')
                ->addValidateRule('required');
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}